<template>
	<div class="app-container">
		<el-timeline>
			<el-timeline-item v-for="(item,key) in activities" :key="key" type="primary">
				<div style="font-size: 18px;font-weight: 600;padding-right: 10px;margin-bottom: 20px;">{{item.shenhe.fankuiFile == 2?'通过':item.shenhe.fankuiFile == 3?'不通过':'待审核'}} <span v-if="item.shenhe.fankuiFile">{{item.shenhe.fankuiTime}}</span></div>
				<div v-if="!item.shenhe.fankuiFile"
					style="margin: 20px 0;display: flex;flex-direction: row;justify-content: space-between;">
					<div style="flex:1">
						<el-input v-model="form.fankuiContent" type="textarea" placeholder="请输入审核内容"></el-input>
					</div>
					<div style="margin-left: 10px;">
						<el-button type="success" icon="el-icon-check" circle @click="shenpiFun(2,item)"></el-button>
						<el-button type="danger" icon="el-icon-close" circle @click="shenpiFun(3,item)"></el-button>
					</div>
				</div>
				<el-descriptions border :colum="3">
					<el-descriptions-item v-if="item.shenhe.fankuiFile" label="反馈审核" label-class-name="my-label"
						:span="3">{{item.shenhe.fankuiContent}}</el-descriptions-item>
					<el-descriptions-item label="反馈时间" label-class-name="my-label"
						:span="3">{{item.fankuiTime}}</el-descriptions-item>
					<el-descriptions-item label="反馈内容" label-class-name="my-label"
						:span="3">{{item.fankuiContent}}</el-descriptions-item>
					<el-descriptions-item label="反馈附件" label-class-name="my-label" :span="3">
						<myFileUpload :disabled="true" ref="myFileUpload" type="img" :fileList="item.fankuiFile">
						</myFileUpload>
					</el-descriptions-item>
				</el-descriptions>
			</el-timeline-item>
		</el-timeline>
	</div>
</template>

<script>
	import myFileUpload from './newUploadFile.vue'
	import dayjs from "dayjs";
	import shenheApi from '@/api/shenhe';
	import taskDeptApi from '@/api/taskdept';
	export default {
		name: "Notice",
		components: {
			myFileUpload
		},
		data() {
			return {
				form: {
					fankuiContent: null
				},
				activities: [],
				// [{
				//          content: '支持使用图标',
				//          timestamp: '2018-04-12 20:46',
				//          size: 'large',
				//          type: 'primary',
				//          icon: 'el-icon-more',
				// 	  status: 1,
				//        }, {
				//          content: '支持自定义颜色',
				//          timestamp: '2018-04-03 20:46',
				//          color: '#0bbd87'
				//        }, {
				//          content: '支持自定义尺寸',
				//          timestamp: '2018-04-03 20:46',
				//          size: 'large'
				//        }, {
				//          content: '默认样式的节点',
				//          timestamp: '2018-04-03 20:46'
				//        }],
				isDay: null
			};
		},
		created() {
			this.isDay = dayjs().format('YYYY-MM-DD')
		},
		methods: {
			shenpiFun(type, item) {
				if (!this.form.fankuiContent) {
					this.$message.warning('审批意见不能为空')
					return
				}
				this.$confirm(`${type == 2?'是否通过审核':'是否驳回审核'}`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let obj = {
						fankuiContent: this.form.fankuiContent,
						fankuiFile: type,
						fankuiTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
						taskId: item.taskId,
						fankuiBackup1: item.fankuiBackup1,
						fankuiBackup2: item.id,
						id: new Date().getTime()
					}
					console.log(obj)
					shenheApi.postOrPutModel(obj).then(res => {
						console.log('shenheApi.postOrPutModel',res)
						if (res.code == 200) {
							taskDeptApi.putModelById(item.fankuiBackup1, {
								taskStatus: type
							}).then(res => {
								this.$set(item,'shenhe',obj)
								this.$message.success('审核成功')
							}).catch(err => {
								console.log(err)
								this.$message.error('审核失败')
							})
						}
					}).catch(err => {
						console.log(err)
						this.$message.error('审核失败')
					})
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.my-label {
		width: 100px;
	}
</style>